<!--
 * @Description: 商品详情页面组件
 -->
<template>
  <div id="details">

    <!-- 主要内容 -->
    <div class="main">
      <!-- 左侧商品图片集合 -->
      <div class="block">
        <div class="div-img-intro">
          <el-row>
            <el-col :span="18">
              <div class="div-content">
                <el-image class="img-def" :src="defImg" fit="contain"/>
              </div>
            </el-col>
            <!-- 左侧游戏图片列表 -->
            <el-col :span="6">
              <div class="div-img-list">
                <div class="div-img-item" v-for="item in imgUrlList" :key="item.id">
                  <button @click="changeImg(item.imgUrl)">
                    <el-image :src="item.imgUrl" ></el-image>
                  </button>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
        <!-- 游戏介绍 start -->
        <div class="div-game-intro">

        </div>
        <!-- 游戏介绍 end -->

      </div>
      <!-- 左侧商品轮播图END -->

      <!-- 右侧内容区 -->
      <div class="content">
        <div class="div-game-sale">
          <el-card style="border-radius: 10px;">
            <h1 class="name">{{ periGoodsInfo.name }}</h1>
            <div class="price">
              <span>￥ {{ periGoodsInfo.seckillPrice }}元</span>
              <!-- 原价 -->
              <span v-show="periGoodsInfo.price != null" class="del">
                {{ periGoodsInfo.price }}元
              </span>
              <el-tag v-show="periGoodsInfo.seckillPercentage != null" class="span-percentage">
                %{{periGoodsInfo.seckillPercentage}}
              </el-tag>
            </div>

            <div class="number">
              <el-input-number v-model="num" :min="1" :max="periGoodsInfo.seckillLimit == null ? periGoodsInfo.saleCount : periGoodsInfo.seckillLimit"/>
            </div>

            <!-- 内容区底部按钮 -->
            <div class="button">
              <el-button class="shop-cart" :disabled="dis" @click="">加入购物车</el-button>
              <el-button class="like" >买它</el-button>
            </div>
            <!-- 内容区底部按钮END -->
          </el-card>
        </div>

      </div>
      <!-- 右侧内容区END -->
    </div>

    <div class="attr">
      <el-tabs type="border-card">
        <el-tab-pane :label="item.attGroupName"  v-for="item in periGoodsAttrList" :key="item.attrGroupId">
          <p v-if="item.attrGroupId == null" v-html="item.attrGroupValue" style="line-height: 50px">
          </p>
          <p v-else class="p-attr" v-for="ele in item.attrList" :key="ele.attrId">
            {{ele.attrName}} : {{ele.attrValue}}
          </p>
        </el-tab-pane>
      </el-tabs>
    </div>

    <div class="introImage">
      <div v-for="imgItem in periGoodsIntroImageList" :key="imgItem.id">
        <el-image :src="imgItem.imgUrl"></el-image>
      </div>
    </div>
    <!-- 主要内容END -->
  </div>
</template>
<script>
import {mapActions, mapGetters} from "vuex";
import periGoods from "@/api/perimall/periGoods";
import periGoodsAttr from "@/api/perimall/periGoodsAttr";
import periGoodsIntroImage from "@/api/perimall/periGoodsIntroImage";

export default {
  data() {
    return {
      dis: false, // 控制“加入购物车按钮是否可用”
      periGoodsId: "", // 商品id
      periGoodsInfo: "", // 商品详细信息
      defImg: '',  //默认图片
      num: 1, //默认购买数量
      imgUrlList: [], //商品图片预览信息
      productPicture: "", // 商品图片
      shoppingCartEntity: {}, //商品购物车信息
      periGoodsAttrList: {},  //周边商品属性
      periGoodsIntroImageList: {}, //周边商品简介图片
    };
  },
  computed: {
    ...mapGetters(["getWishGameIds", "getWishGame"])
  },
  // 通过路由获取商品id
  activated() {
    if (this.$route.query.periGoodsId != undefined) {
      this.periGoodsId = this.$route.query.periGoodsId
      //获取周边商品详情
      this.getPeriGoodsDetailInfo(this.periGoodsId)
      //获取商品的属性值信息
      this.getPeriGoodsAttr(this.periGoodsId)
      //获取周边商品的介绍图片
      this.getPeriGoodsIntroImageInfo(this.periGoodsId)
    }
  },
  watch: {
    // 监听商品id的变化，请求后端获取商品数据
    productID: function (val) {
      this.getDetails(val);
    }
  },
  methods: {
    ...mapActions(["setShoppingCartNum", "checkIsLogin"]),

    //周边商品详情
    getPeriGoodsDetailInfo(id) {
      periGoods.getPeriGoodsDetail(id)
      .then(res => {
        const data = res.data
        if (data != null) {
          this.periGoodsInfo = data
          this.defImg = data.defImg
          this.imgUrlList = data.images
        }
      }).catch(err => {

      })
    },

    //获取商品的属性值
    getPeriGoodsAttr(id) {
      periGoodsAttr.getPeriGoodsAttr(id)
      .then(res => {
        const data = res.data
        this.periGoodsAttrList =data
      }).catch(err => {

      })
    },

    //获取商品的商品简介图片
    getPeriGoodsIntroImageInfo(id) {
      periGoodsIntroImage.getPeriGoodsIntroImage(id)
      .then(res => {
        const data = res.data
        this.periGoodsIntroImageList = data
      }).catch(err => {

      })
    },

    //修改图片
    changeImg(val) {
      this.defImg = val
    }
  }
};
</script>
<style>
/* 头部CSS */
#details .page-header {
  height: 64px;
  margin-top: -20px;
  z-index: 4;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  -webkit-box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.07);
  box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.07);
}

#details .page-header .title {
  width: 1225px;
  height: 64px;
  line-height: 64px;
  font-size: 18px;
  font-weight: 400;
  color: #212121;
  margin: 0 auto;
}

#details .page-header .title p {
  float: left;
}

#details .page-header .title .list {
  height: 64px;
  float: right;
}

#details .page-header .title .list li {
  float: left;
  margin-left: 20px;
}

#details .page-header .title .list li a {
  font-size: 14px;
  color: #616161;
}

#details .page-header .title .list li a:hover {
  font-size: 14px;
  color: #ff6700;
}

/* 头部CSS END */

/* 属性 */
.attr {
  width: 1225px;
  padding-top: 30px;
  margin: 0 auto;
}

.p-attr {
  width: 300px;
  text-align: left;
  padding-left: 30px;
  color: #6a737d;
  margin-right: 20px;
  margin-top: 5px;
  display: inline-block;
  font-size: 15px;
}

.introImage {
  width: 1225px;
  padding-top: 30px;
  margin: 0 auto;
}

/* 主要内容CSS */
#details .main {
  width: 1225px;
  height: 400px;
  padding-top: 30px;
  margin: 0 auto;
}

#details .main .block {
  float: left;
  width: 700px;
  /*height: 560px;*/
}

#details .el-carousel .el-carousel__indicator .el-carousel__button {
  background-color: rgba(163, 163, 163, 0.8);
}

#details .main .content {
  float: right;
  width: 500px;
}

#details .main .content .name {
  height: 30px;
  line-height: 30px;
  font-size: 30px;
  font-weight: normal;
  /*color: #fcfcfc;*/
  padding-left: 10px;
  padding-top: 10px;
  font-family: 华文行楷;
}

#details .main .content .intro {
  color: #b0b0b0;
  padding-left: 10px;
  padding-top: 10px;
}

#details .main .content .store {
  color: #ff6700;
  padding-top: 10px;
}

#details .main .content .price {
  margin-top: 3.5rem;
  display: block;
  font-size: 18px;
  color: #ff6700;
  padding: 25px 0 25px;
}

#details .main .content .number {
  padding: 0 0 25px;
  border-bottom: 1px solid #e0e0e0;
}


#details .main .content .price .del {
  font-size: 14px;
  margin-left: 10px;
  color: #b0b0b0;
  text-decoration: line-through;
}

.span-percentage {
  margin-left: 10px;
  color: #ff6700;
}

#details .main .content .pro-list {
  background: #f9f9fa;
  padding: 30px 60px;
  margin: 50px 0 50px;
}

#details .main .content .pro-list span {
  line-height: 30px;
  color: #616161;
}

#details .main .content .pro-list .pro-price {
  float: right;
}

#details .main .content .pro-list .pro-price .pro-del {
  margin-left: 10px;
  text-decoration: line-through;
}

#details .main .content .pro-list .price-sum {
  color: #ff6700;
  font-size: 24px;
  padding-top: 20px;
}

#details .main .content .button {
  height: 55px;
  margin: 10px 0 0 0;
  padding-left: 10px;
}

#details .main .content .button .el-button {
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}

#details .main .content .button .shop-cart {
  width: 160px;
  background-color: #ff6700;
}

#details .main .content .button .shop-cart:hover {
  background-color: #f25807;
}

#details .main .content .button .like {
  width: 220px;
  margin-left: 40px;
  background-color: #2a80ef;
}

#details .main .content .button .like:hover {
  background-color: #1770e8;
}

#details .main .content .pro-policy li {
  float: left;
  margin-right: 20px;
  color: #b0b0b0;
}

/* 主要内容CSS END */

.img-def {
  width: 100%;
  height: 300px;
  border-radius: 10px;
  /*background-color: #6a737d;*/
}

.div-img-list {
  margin-left: 10px;
  width: 100%;
  height: 300px;
  overflow: auto;
  position: relative;
}

.div-img-item {
  position: relative;
}

.div-img-item button {
  background-color: white;
}

.div-img-item button:hover{
  background-color: #2a80ef;
}

.div-img-item img {
  /*border-radius: 10px;*/
  width: 140px;
  height: 80px;
}

.div-game-sale {
  margin-bottom: 10px;
  border-radius: 10px;
}

.div-game-attr-list h3 {
  padding-left: 20px;
  padding-bottom: 10px;
  text-align: left;
}

.div-game-attr-list div {
  padding-left: 10px;
  padding-bottom: 10px;
}

.div-game-intro {
  margin-top: 10px;
  border-radius: 10px;
}

.div-game-intro h3 {
  padding-left: 20px;
  padding-top: 5px;
  margin-bottom: 10px;
}

.div-game-intro p {
  padding: 0 5px 10px 5px;
  text-indent: 10px;
}

.div-game-update h3 {
  padding-left: 20px;
  padding-top: 5px;
}

.div-game-comment h3 {
  padding-left: 20px;
  padding-top: 5px;
}

.div-comment-left a{
  margin-bottom: 30px;
  margin-left: 5px;
  font-size: 15px;
}

.div-comment-right p {
  margin-top: 5px;
  font-size: 15px;
  letter-spacing: 2px;
  display: -webkit-box;  /*  display: -webkit-box; 必须结合的属性 ，将对象作为弹性伸缩盒子模型显示  */
  -webkit-box-orient: vertical; /*  -webkit-box-orient 必须结合的属性 ，设置或检索伸缩盒对象的子元素的排列方式  */
  -webkit-line-clamp: 4; /*  -webkit-line-clamp用来限制在一个块元素显示的文本的行数 */
  overflow: hidden;
}
</style>